﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace L07
{
    class Program
    {
        static void Main()
        {
            Cock cock = new Cock("花花");
            Host host = new Host("祖儮");
            host.Foster(cock);
            Dog dog = new Dog("阿黄");
            dog.Owner = host;
            Cat cat = new Cat("阿咪");
            cat.Owner = host;
            Sun.Rise();
            Console.ReadKey();
        }
    }
    public static class Sun
    {

        public static event EventHandler OnRise;
        public static void Rise()
        {
            Console.WriteLine("太阳从东边升起....");
            if (OnRise != null)
            {
                OnRise(null, null);
            }
        }
    }
    public class Cock
    {
        private string name;
        public Cock(string name)
        {
            this.name = name;
            Sun.OnRise += new EventHandler(Sun_OnRise);
        }
        private void Sun_OnRise(object sender, EventArgs e)
        {
            Console.WriteLine("公鸡{0}:", name);
            Console.WriteLine("雄鸡一唱天下白");
            this.sing();
        }
        public event EventHandler OnSing;
        public void sing()
        {
            Console.WriteLine("喔喔喔...");
            if (OnSing != null)
            {
                OnSing(null, null);
            }
        }
    }
    public class Host
    {
        private string name;
        public Host(string name)
        {
            this.name = name;
        }
        public event EventHandler OnGetup;
        public void Getup()
        {
            Console.WriteLine("日出而作...");
            if (OnGetup != null)
            {
                OnGetup(null, null);
            }
        }
        public void Foster(Cock c1)
        {
            c1.OnSing += new EventHandler(c1_OnSing);
        }
        private void c1_OnSing(object sender, EventArgs e)
        {
            Console.WriteLine("主人{0}:", name);
            Console.WriteLine("闻鸡起舞!");
            this.Getup();
        }
    }
    public class Dog
    {
        private string name;
        private Host owner;
        public Host Owner
        {
            get { return this.Owner; }
            set
            {
                this.owner = value;
                this.owner.OnGetup += new EventHandler(owner_OnGetup);
            }
        }
        public Dog(string name)
        {
            this.name = name;
        }
        private void owner_OnGetup(object sender, EventArgs e)
        {
            Console.WriteLine("主人{0}:", name);
            Console.WriteLine("汪汪...");
        }
    }
    public class Cat
    {
        private string name;
        private Host owner;
        public Host Owner
        {
            get
            {
                return this.owner;
            }
            set
            {
                this.owner = value;
                this.owner.OnGetup += new EventHandler(owner_OnGetup);
            }
        }
        public Cat(string name)
        {
            this.name = name;
        }
        private void owner_OnGetup(object sender, EventArgs e)
        {
            Console.WriteLine("主人{0}:", name);
            Console.WriteLine("喵喵...");
        }
    }
}


